// carousel.js
document.addEventListener('DOMContentLoaded', function() {
    const carouselContainer = document.querySelector('.carousel-slides');
    const carouselSlides = document.querySelectorAll('.carousel-slide');
    const prevButton = document.querySelector('.carousel-control.prev');
    const nextButton = document.querySelector('.carousel-control.next');
    const carouselIndicators = document.querySelectorAll('.indicator');

    let currentCarousel = 0;
    const totalSlides = carouselSlides.length;

    // 更新轮播图位置
    function updateCarouselPosition() {
        const percentage = (currentCarousel / (totalSlides - 1)) *50;
        carouselContainer.style.transform = `translateX(-${percentage}%)`;

        // 更新指示器状态
        carouselIndicators.forEach((indicator, index) => {
            indicator.classList.toggle('active', index === currentCarousel);
        });
    }

    // 下一张
    function nextCarousel() {
        currentCarousel = (currentCarousel + 1) % totalSlides;
        updateCarouselPosition();
    }

    // 上一张
    function prevCarouselSlide() {
        currentCarousel = (currentCarousel - 1 + totalSlides) % totalSlides;
        updateCarouselPosition();
    }

    // 绑定按钮事件
    nextButton.addEventListener('click', nextCarousel);
    prevButton.addEventListener('click', prevCarouselSlide);

    // 绑定指示器事件
    carouselIndicators.forEach((indicator, index) => {
        indicator.addEventListener('click', () => {
            currentCarousel = index;
            updateCarouselPosition();
        });
    });

    // 自动轮播
    setInterval(nextCarousel, 5000);
});
